package qldc.pm.tiensu.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.DateUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.util.PortalUtil;

import qldc.pm.tiensu.service.ClpSerializer;
import qldc.pm.tiensu.service.DoiTuongTienSuLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class DoiTuongTienSuClp extends BaseModelImpl<DoiTuongTienSu>
    implements DoiTuongTienSu {
    private long _doiTuongTienSuId;
    private long _userId;
    private String _userUuid;
    private String _userName;
    private Date _createDate;
    private Date _modifiedDate;
    private String _soDinhDanhCaNhan;
    private Boolean _xoaAnTich;
    private BaseModel<?> _doiTuongTienSuRemoteModel;

    public DoiTuongTienSuClp() {
    }

    @Override
    public Class<?> getModelClass() {
        return DoiTuongTienSu.class;
    }

    @Override
    public String getModelClassName() {
        return DoiTuongTienSu.class.getName();
    }

    @Override
    public long getPrimaryKey() {
        return _doiTuongTienSuId;
    }

    @Override
    public void setPrimaryKey(long primaryKey) {
        setDoiTuongTienSuId(primaryKey);
    }

    @Override
    public Serializable getPrimaryKeyObj() {
        return _doiTuongTienSuId;
    }

    @Override
    public void setPrimaryKeyObj(Serializable primaryKeyObj) {
        setPrimaryKey(((Long) primaryKeyObj).longValue());
    }

    @Override
    public Map<String, Object> getModelAttributes() {
        Map<String, Object> attributes = new HashMap<String, Object>();

        attributes.put("doiTuongTienSuId", getDoiTuongTienSuId());
        attributes.put("userId", getUserId());
        attributes.put("userName", getUserName());
        attributes.put("createDate", getCreateDate());
        attributes.put("modifiedDate", getModifiedDate());
        attributes.put("soDinhDanhCaNhan", getSoDinhDanhCaNhan());
        attributes.put("xoaAnTich", getXoaAnTich());

        return attributes;
    }

    @Override
    public void setModelAttributes(Map<String, Object> attributes) {
        Long doiTuongTienSuId = (Long) attributes.get("doiTuongTienSuId");

        if (doiTuongTienSuId != null) {
            setDoiTuongTienSuId(doiTuongTienSuId);
        }

        Long userId = (Long) attributes.get("userId");

        if (userId != null) {
            setUserId(userId);
        }

        String userName = (String) attributes.get("userName");

        if (userName != null) {
            setUserName(userName);
        }

        Date createDate = (Date) attributes.get("createDate");

        if (createDate != null) {
            setCreateDate(createDate);
        }

        Date modifiedDate = (Date) attributes.get("modifiedDate");

        if (modifiedDate != null) {
            setModifiedDate(modifiedDate);
        }

        String soDinhDanhCaNhan = (String) attributes.get("soDinhDanhCaNhan");

        if (soDinhDanhCaNhan != null) {
            setSoDinhDanhCaNhan(soDinhDanhCaNhan);
        }

        Boolean xoaAnTich = (Boolean) attributes.get("xoaAnTich");

        if (xoaAnTich != null) {
            setXoaAnTich(xoaAnTich);
        }
    }

    @Override
    public long getDoiTuongTienSuId() {
        return _doiTuongTienSuId;
    }

    @Override
    public void setDoiTuongTienSuId(long doiTuongTienSuId) {
        _doiTuongTienSuId = doiTuongTienSuId;

        if (_doiTuongTienSuRemoteModel != null) {
            try {
                Class<?> clazz = _doiTuongTienSuRemoteModel.getClass();

                Method method = clazz.getMethod("setDoiTuongTienSuId",
                        long.class);

                method.invoke(_doiTuongTienSuRemoteModel, doiTuongTienSuId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public long getUserId() {
        return _userId;
    }

    @Override
    public void setUserId(long userId) {
        _userId = userId;

        if (_doiTuongTienSuRemoteModel != null) {
            try {
                Class<?> clazz = _doiTuongTienSuRemoteModel.getClass();

                Method method = clazz.getMethod("setUserId", long.class);

                method.invoke(_doiTuongTienSuRemoteModel, userId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getUserUuid() throws SystemException {
        return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
    }

    @Override
    public void setUserUuid(String userUuid) {
        _userUuid = userUuid;
    }

    @Override
    public String getUserName() {
        return _userName;
    }

    @Override
    public void setUserName(String userName) {
        _userName = userName;

        if (_doiTuongTienSuRemoteModel != null) {
            try {
                Class<?> clazz = _doiTuongTienSuRemoteModel.getClass();

                Method method = clazz.getMethod("setUserName", String.class);

                method.invoke(_doiTuongTienSuRemoteModel, userName);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public Date getCreateDate() {
        return _createDate;
    }

    @Override
    public void setCreateDate(Date createDate) {
        _createDate = createDate;

        if (_doiTuongTienSuRemoteModel != null) {
            try {
                Class<?> clazz = _doiTuongTienSuRemoteModel.getClass();

                Method method = clazz.getMethod("setCreateDate", Date.class);

                method.invoke(_doiTuongTienSuRemoteModel, createDate);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public Date getModifiedDate() {
        return _modifiedDate;
    }

    @Override
    public void setModifiedDate(Date modifiedDate) {
        _modifiedDate = modifiedDate;

        if (_doiTuongTienSuRemoteModel != null) {
            try {
                Class<?> clazz = _doiTuongTienSuRemoteModel.getClass();

                Method method = clazz.getMethod("setModifiedDate", Date.class);

                method.invoke(_doiTuongTienSuRemoteModel, modifiedDate);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getSoDinhDanhCaNhan() {
        return _soDinhDanhCaNhan;
    }

    @Override
    public void setSoDinhDanhCaNhan(String soDinhDanhCaNhan) {
        _soDinhDanhCaNhan = soDinhDanhCaNhan;

        if (_doiTuongTienSuRemoteModel != null) {
            try {
                Class<?> clazz = _doiTuongTienSuRemoteModel.getClass();

                Method method = clazz.getMethod("setSoDinhDanhCaNhan",
                        String.class);

                method.invoke(_doiTuongTienSuRemoteModel, soDinhDanhCaNhan);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public Boolean getXoaAnTich() {
        return _xoaAnTich;
    }

    @Override
    public void setXoaAnTich(Boolean xoaAnTich) {
        _xoaAnTich = xoaAnTich;

        if (_doiTuongTienSuRemoteModel != null) {
            try {
                Class<?> clazz = _doiTuongTienSuRemoteModel.getClass();

                Method method = clazz.getMethod("setXoaAnTich", Boolean.class);

                method.invoke(_doiTuongTienSuRemoteModel, xoaAnTich);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    public BaseModel<?> getDoiTuongTienSuRemoteModel() {
        return _doiTuongTienSuRemoteModel;
    }

    public void setDoiTuongTienSuRemoteModel(
        BaseModel<?> doiTuongTienSuRemoteModel) {
        _doiTuongTienSuRemoteModel = doiTuongTienSuRemoteModel;
    }

    public Object invokeOnRemoteModel(String methodName,
        Class<?>[] parameterTypes, Object[] parameterValues)
        throws Exception {
        Object[] remoteParameterValues = new Object[parameterValues.length];

        for (int i = 0; i < parameterValues.length; i++) {
            if (parameterValues[i] != null) {
                remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
            }
        }

        Class<?> remoteModelClass = _doiTuongTienSuRemoteModel.getClass();

        ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

        Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

        for (int i = 0; i < parameterTypes.length; i++) {
            if (parameterTypes[i].isPrimitive()) {
                remoteParameterTypes[i] = parameterTypes[i];
            } else {
                String parameterTypeName = parameterTypes[i].getName();

                remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
            }
        }

        Method method = remoteModelClass.getMethod(methodName,
                remoteParameterTypes);

        Object returnValue = method.invoke(_doiTuongTienSuRemoteModel,
                remoteParameterValues);

        if (returnValue != null) {
            returnValue = ClpSerializer.translateOutput(returnValue);
        }

        return returnValue;
    }

    @Override
    public void persist() throws SystemException {
        if (this.isNew()) {
            DoiTuongTienSuLocalServiceUtil.addDoiTuongTienSu(this);
        } else {
            DoiTuongTienSuLocalServiceUtil.updateDoiTuongTienSu(this);
        }
    }

    @Override
    public DoiTuongTienSu toEscapedModel() {
        return (DoiTuongTienSu) ProxyUtil.newProxyInstance(DoiTuongTienSu.class.getClassLoader(),
            new Class[] { DoiTuongTienSu.class },
            new AutoEscapeBeanHandler(this));
    }

    @Override
    public Object clone() {
        DoiTuongTienSuClp clone = new DoiTuongTienSuClp();

        clone.setDoiTuongTienSuId(getDoiTuongTienSuId());
        clone.setUserId(getUserId());
        clone.setUserName(getUserName());
        clone.setCreateDate(getCreateDate());
        clone.setModifiedDate(getModifiedDate());
        clone.setSoDinhDanhCaNhan(getSoDinhDanhCaNhan());
        clone.setXoaAnTich(getXoaAnTich());

        return clone;
    }

    @Override
    public int compareTo(DoiTuongTienSu doiTuongTienSu) {
        int value = 0;

        value = DateUtil.compareTo(getCreateDate(),
                doiTuongTienSu.getCreateDate());

        if (value != 0) {
            return value;
        }

        return 0;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof DoiTuongTienSuClp)) {
            return false;
        }

        DoiTuongTienSuClp doiTuongTienSu = (DoiTuongTienSuClp) obj;

        long primaryKey = doiTuongTienSu.getPrimaryKey();

        if (getPrimaryKey() == primaryKey) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return (int) getPrimaryKey();
    }

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(15);

        sb.append("{doiTuongTienSuId=");
        sb.append(getDoiTuongTienSuId());
        sb.append(", userId=");
        sb.append(getUserId());
        sb.append(", userName=");
        sb.append(getUserName());
        sb.append(", createDate=");
        sb.append(getCreateDate());
        sb.append(", modifiedDate=");
        sb.append(getModifiedDate());
        sb.append(", soDinhDanhCaNhan=");
        sb.append(getSoDinhDanhCaNhan());
        sb.append(", xoaAnTich=");
        sb.append(getXoaAnTich());
        sb.append("}");

        return sb.toString();
    }

    @Override
    public String toXmlString() {
        StringBundler sb = new StringBundler(25);

        sb.append("<model><model-name>");
        sb.append("qldc.pm.tiensu.model.DoiTuongTienSu");
        sb.append("</model-name>");

        sb.append(
            "<column><column-name>doiTuongTienSuId</column-name><column-value><![CDATA[");
        sb.append(getDoiTuongTienSuId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>userId</column-name><column-value><![CDATA[");
        sb.append(getUserId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>userName</column-name><column-value><![CDATA[");
        sb.append(getUserName());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>createDate</column-name><column-value><![CDATA[");
        sb.append(getCreateDate());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
        sb.append(getModifiedDate());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>soDinhDanhCaNhan</column-name><column-value><![CDATA[");
        sb.append(getSoDinhDanhCaNhan());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>xoaAnTich</column-name><column-value><![CDATA[");
        sb.append(getXoaAnTich());
        sb.append("]]></column-value></column>");

        sb.append("</model>");

        return sb.toString();
    }
}
